<template>
  <div>
    <div style="width: 100%;height: 100px;">
      <a-form formLayout="horizontal" :label-col="{ span: 5 }" :wrapper-col="{ span: 18 }">
        <a-row :gutter="[16, 8]">
          <!--          <a-col :span="4">-->
          <!--            <a-button-group >-->
          <!--              <a-button @click="whole()">-->
          <!--                全部-->
          <!--              </a-button>-->
          <!--              <a-button @click="classA()">-->
          <!--                甲班-->
          <!--              </a-button>-->
          <!--              <a-button @click="classB()">-->
          <!--                乙班-->
          <!--              </a-button>-->
          <!--              <a-button @click="classC()">-->
          <!--                丙班-->
          <!--              </a-button>-->‘
		  
          <!--            </a-button-group>-->
          <!--          </a-col>-->
          <a-col :span="4">
            <a-space>
              <a-button icon="left" @click.stop="goPrev" />
              <a-date-picker
                v-model:value="currentMonth"
                placeholder="选择日期"
                :allowClear="false"
                @change="onChangeDate"
              />
              <a-button icon="right" @click.stop="goNext" />
            </a-space>
          </a-col>
          <a-col :span="4">
            <a-form-model-item label="姓名" prop="realname">
              <a-input v-model="queryParam.realname" placeholder="请输入姓名" />
            </a-form-model-item>
          </a-col>
          <a-col :span="4">
            <a-form-model-item label="工号" prop="workNo">
              <a-input v-model="queryParam.workNo" placeholder="请输入工号" />
            </a-form-model-item>
          </a-col>
         <a-col :span="4">
           <a-form-model-item label="车间" prop="workshop">
             <j-multi-select-tag placeholder="请选择车间" v-model="queryParam.workshop" dictCode="workshop" />
           </a-form-model-item>
         </a-col>
         <a-col :span="4">
           <a-form-model-item label="班次" prop="shift">
             <j-dict-select-tag placeholder="请选择班次" v-model="queryParam.shift_dictText" dictCode="shift" />
           </a-form-model-item>
         </a-col>
          <a-col :span="4">
            <a-form-model-item label="品种" prop="variety">
              <j-dict-select-tag
                placeholder="请选择"
                v-model="queryParam.aproductType"
                dictCode="crm_product_type_spooling,product_type,id"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form>
      <a-row :gutter="16" style="margin-top: 10px;">
        <a-col :span="24">
          <a-space style="float: right">
            <a-button @click="handleExportXls('并条')" type="default" icon="export">导出报表</a-button>
            <a-button @click="handleSearch()" type="primary" style="width: 100%">
              搜索
            </a-button>
            <a-button @click="handleAdd" type="primary">新增</a-button>
            <a-button @click="generateSalary()" type="primary" style="width: 100%">
              生成报表
            </a-button>
            <a-button @click="ExportLengthReport('并条长度报表')" style="width: 100%">导出长度报表</a-button>
            <!-- <a-button @click="ExportReport()" style="width: 100%">导出报表</a-button> -->
          </a-space>
        </a-col>
      </a-row>
    </div>
    <div style="margin-top: 15px;">
      <a-table :columns="columns" rowKey="id" :data-source="dataSource" :scroll="{ x: 6500 }" :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
               @change="handleTableChange">
        <!-- 操作 -->
        <a-space slot="action" slot-scope="text, record">
          <template>
            <a-button style="padding: 0px" type="link" icon="edit" @click="handleEdit(record)">编辑</a-button>
            <a-popconfirm title="确认要删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button style="color: red; padding: 0px" type="link" icon="delete">删除</a-button>
            </a-popconfirm>
          </template>
        </a-space>
      </a-table>
    </div>
    <bing-tiao-modal ref="modalForm" @ok="modalFormOk" :planTime="queryParam.planTime"></bing-tiao-modal>
  </div>
</template>

<script>
import { downFile } from '@/api/manage'
import { getGenerateSalaryDataDrawing } from '../../../api/customApi'
import { JeecgListMixin } from '../../../mixins/JeecgListMixin'
import BingTiaoModal from './modules/BingTiaoModal'
import moment from 'moment'

const path = '/crm_salary_excel_drawing/crmSalaryExcelDrawing'
export default {
  mixins: [JeecgListMixin],
  components: { BingTiaoModal },
  data() {
    return {
      currentMonth: moment(),
      time: undefined,
      name: '',
      jobId: '',
      riqi: null,
      workshop: undefined,
      variety: undefined,
      jobType: '',
      dataSource,
      columns,
      queryParam: {
        planTime: moment().format('YYYY-MM-DD')
      },
      url: {
        list: path + '/list',
        delete: path + '/delete',
        deleteBatch: path + '/deleteBatch',
        exportXlsUrl: '/crm_salary_excel_drawing/crmSalaryExcelDrawing/exportExcel',
        exportLengthXlsUrl: '/crm_salary_excel_drawing/crmSalaryExcelDrawing/exportLengthExcel'
      }
    }
  },
  methods: {
    goPrev() {
      var newMonth = moment(this.currentMonth).subtract(1, 'day')
      this.currentMonth = newMonth
      this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
      this.searchQuery()
    },
    goNext() {
      var newMonth = moment(this.currentMonth).add(1, 'day')
      this.currentMonth = newMonth
      this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
      this.searchQuery()
    },
    onChangeDate(date, dateString) {
      this.queryParam.planTime = dateString
      this.searchQuery()
    },
    changeObject() {},
    refresh() {
      this.searchQuery()
    },
    handleSearch() {
      this.searchQuery()
      this.visible = false
    },
    handleCancel() {
      this.visible = false
    },
    handleReset() {
      this.searchReset()
    },
    add() {
      this.visable1 = true
    },
    detail(record) {},
    onChangePage(e) {
      this.ipagination.current = e
      this.loadData()
    },
    generateSalary() {
      let query = {
        planTime: this.queryParam.planTime
      }
      getGenerateSalaryDataDrawing(query).then(res => {
        if (res.success) {
          this.$message.success('生成成功')
          this.searchQuery()
        }
      })
    },

    whole() {},
    classA() {},
    classB() {},
    ExportLengthReport(fileName) {
      if (!fileName || typeof fileName != 'string') {
        fileName = '导出文件'
      }
      let param = this.getQueryParams()
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      console.log('导出参数', param)
      downFile(this.url.exportLengthXlsUrl, param).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    ExportReport() {},
    search() {},

    handleChange(value) {
      console.log(`selected ${value}`)
    },

    onChange(date, dateString) {
      console.log(date, dateString)
    }
  }
}
const columns = [
  { title: '日期', width: 200, dataIndex: 'createTime', key: 'createTime', fixed: 'left' },
  { title: '车间', width: 150, dataIndex: 'workshop', key: 'workshop', fixed: 'left' },
  { title: '班次', width: 150, dataIndex: 'shift_dictText', key: 'shift', fixed: 'left' },
  { title: '上班时间', width: 150, dataIndex: 'workHours', key: 'workHours', fixed: 'left' },
  { title: '机台时间', width: 150, dataIndex: 'machineHours', key: 'machineHours', fixed: 'left' },
  { title: '机号', dataIndex: 'deviceNo', key: 'deviceNo', width: 150 },
  // { title: '机型', dataIndex: 'machineType', key: 'machineType', width: 150 },
  // { title: '品种', dataIndex: 'column8', key: 'column8', width: 150 },
  { title: '工号', dataIndex: 'workNo', key: 'workNo', width: 150 },
  { title: '姓名', dataIndex: 'realname', key: 'realname', width: 150 },
  { title: '条桶规格', dataIndex: 'barrelSize', key: 'barrelSize', width: 150 },
  // { title: '品种类别', dataIndex: '品种类别', key: '品种类别',width: 150  },
  // { title: '品种\n', dataIndex: '品种\n', key: 'weight', width: 150 },
  { title: '机台系数', dataIndex: 'machineCoefficient', key: 'machineCoefficient', width: 150 },
  { title: '品种系数', dataIndex: 'productTypeCoefficient', key: 'productTypeCoefficient', width: 150 },
  { title: '单价系数', dataIndex: 'unitPriceCoefficient', key: 'unitPriceCoefficient', width: 150 },
  { title: '综合系数', dataIndex: 'comprehensiveCoefficient', key: 'comprehensiveCoefficient', width: 150 },
  { title: '定量', dataIndex: 'quantify', key: 'quantify', width: 150 },
  { title: '线速度', dataIndex: 'linearVelocity', key: 'linearVelocity', width: 150 },
  { title: '是否二并', dataIndex: 'secondDrawing', key: 'secondDrawing', width: 150 },
  { title: '是否预并', dataIndex: 'preDrawing', key: 'preDrawing', width: 150 },
  { title: '末并定长（桶/m)', dataIndex: 'fixedLengthDrawing', key: 'fixedLengthDrawing', width: 150 },
  { title: '8小时定额长度(千米)', dataIndex: 'fixedLengthEightHours', key: 'fixedLengthEightHours', width: 150 },
  { title: '台数', dataIndex: 'machinesNum', key: 'machinesNum', width: 150 },
  { title: '看台数(8小时)', dataIndex: 'machinesNumEightHours', key: 'machinesNumEightHours', width: 150 },
  { title: '总看台率%', dataIndex: 'totalMachinesRate', key: 'totalMachinesRate', width: 150 },
  { title: '交班长度', dataIndex: 'handoverLength', key: 'handoverLength', width: 150 },
  { title: '接班长度', dataIndex: 'takeoverLength', key: 'takeoverLength', width: 150 },
  { title: '实际长度(百米)', dataIndex: 'realityLength', key: 'realityLength', width: 150 },
  { title: '重量（kg）', dataIndex: 'weight', key: 'weight', width: 150 },
  { title: '预并上条数（台/桶）', dataIndex: 'preDrawingFeedCount', key: 'preDrawingFeedCount', width: 150 },
  {
    title: '预并落桶数（按末并）',
    dataIndex: 'preDrawingBucketDropCount',
    key: 'preDrawingBucketDropCount',
    width: 150
  },
  { title: '头并上条数（台/桶）', dataIndex: 'headDrawingFeedCount', key: 'headDrawingFeedCount', width: 150 },
  { title: '二并上条数（按头并50%)', dataIndex: 'secondDrawingFeedCount', key: 'secondDrawingFeedCount', width: 150 },
  {
    title: '二并落桶数（台/桶）',
    dataIndex: 'secondDrawingBucketDropCount',
    key: 'secondDrawingBucketDropCount',
    width: 150
  },
  {
    title: '二并清洁长度（50%千米）',
    dataIndex: 'secondDrawingCleanLength',
    key: 'secondDrawingCleanLength',
    width: 150
  },
  {
    title: '末并落桶数（台/桶）',
    dataIndex: 'finalDrawingBucketDropCount',
    key: 'finalDrawingBucketDropCount',
    width: 150
  },
  { title: '上条单价（桶/元）', dataIndex: 'feedUnitPrice', key: 'feedUnitPrice', width: 150 },
  { title: '落桶单价（桶/元）', dataIndex: 'bucketDropUnitPrice', key: 'bucketDropUnitPrice', width: 150 },
  {
    title: '清洁看台单价（千米/元）',
    dataIndex: 'cleanInspectionUnitPrice',
    key: 'cleanInspectionUnitPrice',
    width: 150
  },
  { title: '预并上条工资（元）', dataIndex: 'preDrawingFeedWages', key: 'preDrawingFeedWages', width: 150 },
  { title: '头并上条工资（元）', dataIndex: 'headDrawingFeedWages', key: 'headDrawingFeedWages', width: 150 },
  { title: '二并上条工资（元）', dataIndex: 'secondDrawingFeedWages', key: 'secondDrawingFeedWages', width: 150 },
  {
    title: '二并落桶工资（元）',
    dataIndex: 'secondDrawingBucketDropWages',
    key: 'secondDrawingBucketDropWages',
    width: 150
  },
  { title: '二并清洁工资（元）', dataIndex: 'secondDrawingCleanWages', key: 'secondDrawingCleanWages', width: 150 },
  {
    title: '末并落桶工资（元）',
    dataIndex: 'finalDrawingBucketDropWages',
    key: 'finalDrawingBucketDropWages',
    width: 150
  },
  { title: '末并清洁工资（元）', dataIndex: 'finalDrawingCleanWages', key: 'finalDrawingCleanWages', width: 150 },
  { title: '系数补扣', dataIndex: 'coefficientDeduction', key: 'coefficientDeduction', width: 150 },
  { title: '其它补贴', dataIndex: 'otherSubsidies', key: 'otherSubsidies', width: 150 },
  { title: '合计工资', dataIndex: 'totalWages', key: 'totalWages', width: 150 },
  { title: '完成率%', dataIndex: 'completionRate', key: 'completionRate', width: 150 },
  { title: '机台保养', dataIndex: 'machinesMaintenance', key: 'machinesMaintenance', width: 150 },
  { title: '备注', dataIndex: 'remark', key: 'remark', width: 150 },
  { title: '单台看台率', dataIndex: 'singlePlatformViewingRate', key: 'singlePlatformViewingRate', width: 150 },
  { title: '看台审核', dataIndex: 'platformReview', key: 'platformReview', width: 150 },
  // { title: '机台日时间', dataIndex: '机台日时间', key: 'column43', width: 150 },
  // { title: '工号转换\n', dataIndex: '清花品种', key: 'column45', width: 150 },
  // { title: '班次条件\n', dataIndex: '清花品种', key: 'column46', width: 150 },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center',
    scopedSlots: { customRender: 'action' },
    fixed: 'right'
  }
]
const dataSource = [
  {
    column1: 1,
    column2: 1,
    column3: 1,
    column4: 1,
    column5: 1,
    column6: 1,
    column7: 1,
    column8: 1,
    column9: 1,
    column10: 1,
    column11: 1,
    column12: 1,
    column13: 1,
    column14: 1,
    column15: 1,
    column16: 1,
    column17: 1,
    column18: 1,
    column19: 1,
    column20: 1,
    column21: 1,
    column22: 1,
    column23: 1,
    column24: 1,
    column25: 1,
    column26: 1,
    column27: 1,
    column28: 1,
    column29: 1,
    column30: 1,
    column31: 1,
    column32: 1,
    column33: 1,
    column34: 1,
    column35: 1,
    column36: 1,
    column37: 1,
    column38: 1,
    column39: 1,
    column40: 1,
    column41: 1,
    column42: 1,
    column43: 1,
    column44: 1,
    column45: 1
  }
]
</script>

<style scoped></style>
